// pages/morejob/denounce/denounce.js
Page({
  data: {
    postId: "",
    userId: "",
    type: "",
    typeId: "",
    message: "",
    fileList: [],
    imgIds: [],
    show: false,
    actions: [{
        id: 1,
        name: "色情内容"
      },
      {
        id: 2,
        name: "涉嫌刷单"
      },
      {
        id: 3,
        name: "违法犯罪"
      },
    ],
  },
  onLoad: function (options) {
    this.setData({
      postId: options.postId,
      userId: options.userId
    });
  },
  upload(e) {
    getApp().globalData.util.imgsUpload(this, e, this.data.fileList, this.data.imgIds);
  },
  delete(e) {
    let i = e.detail.index;
    let fileList = this.data.fileList;
    let imgIds = this.data.imgIds;
    fileList.splice(i, 1);
    imgIds.splice(i, 1);
    this.setData({
      fileList: fileList,
      imgIds: imgIds
    });
  },
  selReason() {
    this.setData({
      show: true
    });
  },
  onClose() {
    this.setData({
      show: false
    });
  },
  onSelect(e) {
    this.setData({
      type: e.detail.name,
      typeId: e.detail.id
    });
  },
  submit() {
    let params = {
      type: this.data.type,
      message: this.data.message
    }
    if (!params.type) {
      getApp().globalData.vant.toast("请选择举报类型");
    } else if (!params.type) {
      getApp().globalData.vant.toast("请填写举报原因");
    } else {
      getApp().globalData.http.reportSave({
        dataId: this.data.postId,
        violatorsUserId: this.data.userId,
        type: this.data.typeId,
        content: this.data.message,
        imgIds: this.data.imgIds.join(",")
      }).then(res => {
        getApp().globalData.vant.toast({
          type: "success",
          message: "提交成功",
          duration: 1000,
          onClose: () => {
            wx.navigateBack();
          },
        });
      });
    }
  }
})